var http_recvouc = getHTTPObject_recvouc();
var	m_ctrlobj = null;
var	m_ctrlValobj = null;

function GBLVdn_Trim(p_sValue)
{
    if(!p_sValue || typeof p_sValue != 'string')
        return "";

    return p_sValue.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}

function getHTTPObject_recvouc()
{
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} return xmlhttp;
}

function call_DBDuplicate(p_tblname,p_tblcond,p_ctrlObj,p_ctrlValobj)
{	
//alert(p_ctrlObj +""+ p_ctrlValobj);
	m_ctrlObj = p_ctrlObj;
	m_ctrlValobj = p_ctrlValobj;
	
	var vLoading = "<img src='../images/loader.gif' align='absmiddle'>&nbsp;Checking availability...";
	m_ctrlValobj.innerHTML=vLoading;
	
	var url="../ajax/dbdublicate_ajax.jsp?TblName="+ p_tblname +"&TblCond="+ p_tblcond;
//alert(url);
	http_recvouc.open("GET", url, true);
	http_recvouc.onreadystatechange = DBDuplicate_receive;
	http_recvouc.send(null);
}

function DBDuplicate_receive()
{
	
//
	if (http_recvouc.readyState == 4) 
	{
	//alert(http_recvouc.status);		
  	 	if (http_recvouc.status == 200) 
	 	{
			var res= http_recvouc.responseText;
//		alert(res);
			if ( res != null  && (res.indexOf("0") != -1 && m_ctrlObj != null) )
			{
				document.getElementById("hid_DupRec").value = "0";
				var vLoading = "<img src='../images/tick.gif' align='absmiddle'>";
				m_ctrlValobj.innerHTML=vLoading;
				//m_ctrlObj.focus();
			}
			else if ( res != null  && ( res.indexOf("1") != -1 && m_ctrlObj != null) )
			{
				document.getElementById("hid_DupRec").value = "1";				
				var vLoading = "<font color='red'><strong>"+ m_ctrlObj.value +"</strong> is already in use.</font>";
				m_ctrlValobj.innerHTML=vLoading;
				//m_ctrlObj.focus();
			}			
		}
	}	
}

function call_DBDuplicateCallNew(p_tblname,p_tblcond,p_ctrlObj,p_ctrlValobj)
{	
//alert(p_ctrlObj +""+ p_ctrlValobj);
	m_ctrlObj = p_ctrlObj;
	m_ctrlValobj = p_ctrlValobj;
	
	var vLoading = "<img src='images/loader.gif' align='absmiddle'>&nbsp;Checking availability...";
	m_ctrlValobj.innerHTML=vLoading;
	
	var url="ajax/getID_ajax.jsp?TblName="+ p_tblname +"&TblCond="+ p_tblcond;
//alert(url);
	http_recvouc.open("GET", url, true);
	http_recvouc.onreadystatechange = DBDuplicateCallNew_receive;
	http_recvouc.send(null);
}

function DBDuplicateCallNew_receive()
{
//
	if (http_recvouc.readyState == 4) 
	{
	//alert(http_recvouc.status);		
  	 	if (http_recvouc.status == 200) 
	 	{
			var res= http_recvouc.responseText;
		//alert(res);
			res = GBLVdn_Trim(res);
			if ( res != null  && (res.indexOf("-1") != -1 && m_ctrlObj != null) )
			{
				var vLoading = "<font color='red'><strong>"+ m_ctrlObj.value +"</strong> is not found.</font>";
				m_ctrlValobj.innerHTML=vLoading;
				m_ctrlObj.focus();
			}
			else if ( res != null && m_ctrlObj != null )
			{
				m_ctrlValobj.innerHTML ="&nbsp;";
				CallPage(res);
			}			
		}
	}	
}


function call_DBGetTblRecCount(p_tblqry,p_ctrlObj)
{	
	m_ctrlObj = p_ctrlObj;
	var url="ajax/queryValue_ajax.jsp?TblQry="+p_tblqry;
//alert(url);
	http_recvouc.open("GET", url, true);
	http_recvouc.onreadystatechange =GetTblRecCount_receive;
	http_recvouc.send(null);
}

function GetTblRecCount_receive()
{
	if (http_recvouc.readyState == 4) 
	{
	//alert(http_recvouc.readyState);		
  	 	if (http_recvouc.status == 200) 
	 	{
			var res= http_recvouc.responseText;
		//alert(res);
			document.getElementById("DupMsg").innerHTML="";
			if ( res != null && res != "" && m_ctrlObj != null )
			{
				var vQusCount = m_ctrlObj.value;
				if ( Number(vQusCount) > Number(res) )
				{
					var vMSG = res + " Records Only Available";
					document.getElementById("DupMsg").innerHTML=vMSG;
					inlineMsg(m_ctrlObj,vMSG,2);
					m_ctrlObj.focus();
				}
			}
		}
	}	
}

var vAllID = 0 ;
function call_getSubCategory(p_catID,p_vAll)
{	
	vAllID = p_vAll;
	var url="ajax/subcat_ajax.jsp?CatID="+ p_catID;
//alert(vAllID);
	http_recvouc.open("GET", url, true);
	http_recvouc.onreadystatechange = getSubCategory_receive;
	http_recvouc.send(null);
}

function getSubCategory_receive()
{
//
	if (http_recvouc.readyState == 4) 
	{
	//alert(http_recvouc.status);		
  	 	if (http_recvouc.status == 200) 
	 	{
			var res= http_recvouc.responseText;
		//alert(res);
			res = GBLVdn_Trim(res);
			if ( Number(vAllID) == 1 )
				res = "<option value='0' >All</option>" + res;			
		//alert( vAllID +" : "+ res);				
			if ( res != null )
			{
				res = "<select tabindex='2' name='cb_subcategory' id='cb_subcategory' >"+ res +"</option>";
				document.getElementById("td_subcat").innerHTML=res;
			}
			vAllID = 0;
		}
	}	
}

function call_getRptStudent(p_TeacherID,p_ParentID)
{	
	var url="ajax/rpt_stu_ajax.jsp?TeacherID="+ p_TeacherID +"&ParentID="+ p_ParentID;;
//alert(url);
	http_recvouc.open("GET", url, true);
	http_recvouc.onreadystatechange = getRptStudent_receive;
	http_recvouc.send(null);
}

function getRptStudent_receive()
{
//
	if (http_recvouc.readyState == 4) 
	{
	//alert(http_recvouc.status);		
  	 	if (http_recvouc.status == 200) 
	 	{
			var res= http_recvouc.responseText;
		//alert(res);
			res = GBLVdn_Trim(res);
			if ( res != null )
			{
				res = "<select tabindex='4' name='cb_student' id='cb_student' >"+ res +"</option>";
				document.getElementById("td_stu").innerHTML=res;
			}
		}
	}	
}